Method and device for identifying type of variable in binary

ABSTRACT

A method for identifying a type of a variable within a binary performed on a computing device is provided. The method comprises, identifying a variable from disassembly code of a binary, and determining a type of the variable based on an instruction of the disassembly code, associated with the variable.

CROSS-REFERENCE TO RELATED APPLICATION

This application claims priority from Korean Patent Application No.10-2019-0139853 filed on Nov. 5, 2019 in the Korean IntellectualProperty Office, and all the benefits accruing therefrom under 35 U.S.C.119, the contents of the application in its entirety is hereinincorporated by reference.

BACKGROUND 1. Technical Field

The present disclosure relates to a method and device for identifying atype of a variable in a binary. More specifically, it relates to amethod and system for inferring and determining a size of an array andthe type of variables in a binary.

2. Description of the Related Art

In the process of developing a program, generally, one logicallyanalyzes and verifies contents of source code of a program, or one usesa debugging program to set breakpoints in the source code of the programwhere there is a possibility of vulnerability. Then, when the executionis suspended according to the break point during the execution of theprogram, the vulnerability of the program is analyzed by observing theexecution environment of the program. When a program's source code isgiven, a list of variables used in the program and variable types may beidentified on the source code. Therefore, vulnerabilities related tobuffer overflow, integer overflow, and type confusion may be relativelyeasily identified. In addition, when a vulnerability is found, thesource code is corrected to rebuild the program, thereby complementingthe vulnerability.

However, after a program is developed, especially based on a third partywho is not the program's developer analyzing and patching the program'svulnerability, vulnerability analysis and patching are mostly performedon program binaries in environments where source code cannot beobtained. Therefore, the methods described above may not be utilized.For example, information on a type of a variable and a size of a bufferis required to search for a vulnerability, analyze a cause, and patch abinary to compensate for the vulnerability. However, a method forautomatically obtaining the information from a program binary is notprovided.

SUMMARY

Aspects of the present disclosure provide a method and device foridentifying a type of a variable in a binary.

Aspects of the present disclosure also provide a method and device foridentifying a list of local variables used by each of user functionsdefined in a binary.

Aspects of the present disclosure also provide a method and device fordetermining the most reliable type among a plurality of types inferredfor variables in a binary.

Aspects of the present disclosure also provide a method and device fordetermining a size of a variable and array (buffer) used in a userfunction defined in a binary.

However, aspects of the present disclosure are not restricted to thoseset forth herein. The above and other aspects of the present disclosurewill become more apparent to one of ordinary skill in the art to whichthe present disclosure pertains by referencing the detailed descriptionof the present disclosure given below.

According to an aspect of the present disclosure, a method foridentifying a type of a variable within a binary performed on acomputing device is provided. The method comprises, identifying avariable from disassembly code of a binary, and determining a type ofthe variable based on an instruction of the disassembly code, associatedwith the variable.

According to an aspect of the present disclosure, a method foridentifying a size of a variable in a binary performed on a computingdevice is provided. The method comprises identifying a plurality ofvariables from disassembly code of a binary, determining, for each ofthe plurality of variables, an initial value of the size of thevariable, and determining, for each of the plurality of variables, thesize of the variable based on an inferred variable type and the initialvalue of the size of the variable.

According to an aspect of the present disclosure, a device foridentifying a type of a variable in a binary is provided. The devicecomprises, a variable information collection unit, a variable typeinference unit, and a variable type determination unit, wherein thevariable information collection unit, analyzes disassembly code of thebinary, and identifying a plurality of operands as each variable, theoperands accessing a memory using a base pointer register and an indexvalue, and determines an initial value of a variable size for eachvariable based on the index value corresponding to each variable,wherein the variable type inference unit determines a variable typecandidate for each variables based on at least one of an instructionusing each variable as an operand and a standard library function usingeach variable as a parameter, and inferring the type of each variablebased on the variable type candidate, and wherein the variable typedetermination unit determines the type and size of each variable basedon the inferred type of the variable and the initial value of thevariable size.

BRIEF DESCRIPTION OF THE DRAWINGS

The above and other aspects and features of the present disclosure willbecome more apparent by describing in detail exemplary embodimentsthereof with reference to the attached drawings, in which:

FIG. 1 is a view for explaining an exemplary environment in whichinformation on a variable type and size determined by variousembodiments of the present disclosure is used;

FIG. 2 is a block diagram of a device for inferring a type of a variablein a binary according to an embodiment of the present disclosure;

FIG. 3 is a block diagram of a variable information collection unit ofthe device for inferring the type of the variable in the binary shown inFIG. 2;

FIG. 4 is a diagram for explaining the operation of the variableinformation collection unit shown in FIG. 3;

FIGS. 5A and 5B are diagrams for explaining an exemplary method in whicha register analysis component shown in FIG. 3 traces a final value of aregister, and FIG. 5C is a view for explaining an example of variableidentification information generated by the register analysis component;

FIG. 6 is a diagram illustrating exemplary stack frame informationgenerated by a stack frame analysis component illustrated in FIG. 3;

FIG. 7 is a block diagram of a type inference unit of the device forinferring the type of the variable in the binary shown in FIG. 2;

FIG. 8 is a diagram for explaining the operation of the type inferenceunit shown in

FIG. 7;

FIG. 9 is a diagram illustrating exemplary assembly instructions that avariable type inference execution component illustrated in FIG. 7 mayrefer to for inferring a variable type;

FIGS. 10A and 10B are diagrams for explaining a method in which thevariable type inference execution component illustrated in FIG. 7 infersa variable type by referring to a standard library function;

FIG. 11 is a block diagram of a type determination unit of the devicefor inferring the type of the variable in the binary shown in FIG. 2;and

FIGS. 12A and 12B are diagrams for explaining the operation of the typedetermination unit shown in FIG. 11.

DETAILED DESCRIPTION OF THE EMBODIMENTS

Hereinafter, embodiments of the present disclosure will be describedwith reference to the attached drawings. Advantages and features of thepresent disclosure and methods of accomplishing the same may beunderstood more readily by reference to the following detaileddescription of embodiments and the accompanying drawings. The presentdisclosure may, however, be embodied in many different forms and shouldnot be construed as being limited to the embodiments set forth herein.Rather, these embodiments are provided so that this disclosure will bethorough and complete and will fully convey the concept of thedisclosure to those skilled in the art, and the present disclosure maybe defined by the appended claims.

In adding reference numerals to the components of each drawing, itshould be noted that the same reference numerals are assigned to thesame components as much as possible even though they are shown indifferent drawings. In addition, in describing the present disclosure,based on it being determined that the detailed description of therelated well-known configuration or function may obscure the gist of thepresent disclosure, the detailed description thereof will be omitted.

Unless otherwise defined, all terms used in the present specification(including technical and scientific terms) may be used in a sense thatcan be commonly understood by those skilled in the art. In addition, theterms defined in the commonly used dictionaries are not ideally orexcessively interpreted unless they are specifically defined clearly.The terminology used herein is for the purpose of describing embodimentsand is not intended to be limiting of the present disclosure. In thisspecification, the singular also includes the plural unless specificallystated otherwise in the phrase.

In addition, in describing the component of this present disclosure,terms, such as first, second, A, B, (a), (b), can be used. These termsare for distinguishing the components from other components, and thenature or order of the components is not limited by the terms. If acomponent is described as being “connected,” “coupled” or “contacted” toanother component, that component may be directly connected to orcontacted with that other component, but it should be understood thatanother component also may be “connected,” “coupled” or “contacted”between each component.

Hereinafter, some embodiments of the present disclosure will bedescribed in detail with reference to the accompanying drawings.

First, referring to FIG. 1, it will be described that variable type andsize information determined by embodiments of the present disclosure maybe used in a series of processes of patching a vulnerability in aprogram binary. FIG. 1 1 schematically shows a process of patching avulnerability in a program binary.

First, vulnerability identification and patch target binaries 10 aregiven, and vulnerability area search or a vulnerability discoveryprocess 110 for the target binaries 10 may be performed. Thevulnerability search 110 may be performed using various conventionaltechniques such as fuzzing, symbolic execution, and hybrid fuzzingcombining them.

The fuzzing may be a method that creates a situation where a programcrashes by repeatedly generating arbitrary values (test cases) andinputting them into a target program. The symbolic execution may be amethod for specifying an input value of a target program as a symbol andfinding a value that may reach a path of the program's vulnerability.The hybrid fuzzing may be a technique that combines fuzzing and symbolicexecution. It may be a way to use fuzzing in shallow paths to quicklyexplore vulnerabilities, and to search for vulnerabilities by usingsymbolic execution based on a path search no longer being possible.

However, even with hybrid fuzzing, a code area (i.e., coverage) that maysearch for vulnerabilities reaches the limit, and situations in whichcoverage may no longer be increased frequently occur. In order tofurther search unexplored areas that have not been searched byconventional methods for searching vulnerabilities, techniques forchanging a control flow of the target binary 10 have been studied toidentify a user function including unexplored areas and to directly fuzzparameters of the user function.

As described above, in order to expand vulnerability search coverage ofthe target binary 10, information on the type and size of variablesexisting in the binary may be used to be able to directly fuzz theparameters of the user function existing in the binary.

It will be described with reference to FIG. 1 again. A process 120 ofanalyzing a cause of vulnerability may be performed based on informationon vulnerability discovery area and crash information calculated as aresult of performing the vulnerability search 110 for the target binary10. There may be many different causes and types of vulnerabilities inbinaries. From 2010 to 2015, about 80,000 security vulnerabilities(CVEs) were registered in the National Vulnerability Database (NVD),which may be a vulnerability database, and it has been increasingcontinuously in recent years. Some of typical types of various securityvulnerabilities may be buffer overflow or integer overflow types thatstore data exceeding the allocated storage space, a variable type errortype, a vulnerability type used without initializing a variable, etc.Information on the type and size of variables may be used to analyze thetypes and causes of vulnerabilities from vulnerability search results.

Next, a process 130 of patching to remove vulnerabilities of FIG. 1 willbe described. As described above, according to the types and causes ofvarious vulnerabilities, various patch types and patch applicationmethods for removing the vulnerabilities should be selected. Forexample, information on the types and sizes of the variables may be usedin various processes from the step of generating various types of patchcode, such as variable initialization patch, function parameterverification or change patch, control flow change patch, etc., to thestep of selecting patching methods such as function-based patching andinstruction-based patching, and applying a patch.

So far, it has been described with reference to FIG. 1 that variabletype and size information determined by embodiments of the presentdisclosure may be used in a process of patching a vulnerability in aprogram binary. Hereinafter, a method and device for inferring a type ofa variable in a binary according to various embodiments of the presentdisclosure will be described in detail with reference to FIGS. 2 to 12.

FIG. 2 is a block diagram of a device 200 for inferring a type of avariable in a binary according to an embodiment of the presentdisclosure.

The device 200 for inferring the type of the variable in the binaryaccording to the present embodiment may be configured as a variableinformation collection unit 210, a type inference unit 220, and a typedetermination unit 230. The device 200 according to the presentembodiment receives a target binary 10 to be analyzed for variableinformation as an input, and generates and outputs information 20 aboutthe type of the variable and a size of an array for each user functiondefined in the target binary 10.

The variable information collection unit 210 classifies assembly code(or referred to as ‘disassembly code’) calculated by disassembling thetarget binary 10 for each user-defined function, and structures it inunits of assembly instructions. In addition, the variable informationcollection unit 210 identifies variables from the assembly codeclassified for each user-defined function and structured in units ofinstructions. In addition, the variable information collection unit 210initially analyzes a stack frame of each user-defined function from thestructured assembly code. Based on the analysis, stack frame information14 on stack frame blocks corresponding to data stored in the stack framemay be generated.

The variable information collection unit 210, although not shown,provides the structured assembly code to the type inference unit 220 andthe type determination unit 230, which will be described later. Inaddition, the variable information collection unit 210 provides variableidentification information 12 to the type inference unit 220 and thestack frame information 14 to the type determination unit 230. Moredetails regarding the configuration and operation of the variableinformation collection unit 210 will be described later with referenceto FIGS. 3 to 6.

The type inference unit 220 generates variable type inferenceinformation 16 for each user-defined function based on the structuredassembly code (not shown) and variable identification information 12provided from the variable information collection unit 210, and typeinference pattern information. The variable type inference information16 generated by the type inference unit 220 may be provided to the typedetermination unit 230 to be described later. More details regarding theconfiguration and operation of the type inference unit 220 will bedescribed later with reference to FIGS. 7 to 10.

The type determination unit 230 finally determines each variable typeand variable size (including the size of the array) for each userfunction by synthesizing the variable type inference information 16 andthe stack frame information 14. Variable type and size information 20generated by the type determination unit 230 may be used in the processof patching the vulnerability of the binary as described above.

It may be noted that he variable information collection unit 210, thetype inference unit 220, and the type determination unit 230 of thedevice 200 for inferring the type of the variable described so far withreference to FIG. 2 may be implemented in one or two configurationsdepending on embodiments.

Hereinafter, the configuration and operation of the variable informationcollection unit 210 of the device 200 for inferring the type of thevariable will be described in detail with reference to FIGS. 3 to 6.

FIG. 3 is a block diagram of the variable information collection unit210. The variable information collection unit 210 may include anassembly code pre-processing component 212, a register analysiscomponent 214, and a stack frame analysis component 216.

The assembly code pre-processing component 212 generates assembly codeby disassembling the target binary 10 composed of machine language.Here, the assembly code pre-processing component 212 may generateassembly code using a program such as ‘objdump.’ In addition, theassembly code pre-processing component 212 classifies and stores theassembly code for each user-defined function. In addition, the assemblycode pre-processing component 212 structures the assembly codeclassified for each of the user-defined functions in units of assemblyinstructions. For example, a list may be constructed in which eachinstruction included in the assembly code may be a node.

The register analysis component 214 analyzes the structured assemblyinstructions for each user function and identifies a general purposeregister that may be likely a local variable among general registersused as the instruction's operand. Then, it stores identified generalpurpose register information as the variable identification information12.

As a preparation process for this, in one user function, a uniqueidentification value may be given to a general purpose register todistinguish the same general purpose register that has been usedmultiple times to store values of different variables. Also, in a userfunction, instructions for assigning a value to a general purposeregister may be traced to obtain a final value assigned to the generalpurpose register. This will be described later with reference to FIGS.5A and 5B.

The register analysis component 214 may provide the variableidentification information 12 to the type inference unit 220.

The stack frame analysis component 216 identifies operands having apattern estimated as a variable among operands of instructions in theuser function, and generates the stack frame information 14.

Local variables (including arrays) defined in the user function may beallocated storage space in the stack frame allocated to the userfunction during compiling. The storage space for each variable in theassembly code may be accessed using a distance (or may be referred to asa ‘relative address’) from a base pointer register value that stores amemory address of a bottom of the stack frame of the user function.

In assembly code, operands that access a memory using a relative addressto a memory address stored in a base pointer register (e.g., an EBPregister) may be a variable. In other words, operands expressed as basepointer registers and index values (relative addresses) may be estimatedas variables. For example, based on an operand of an assemblyinstruction being 0xN(% ebp) or −0xN(% ebp) (where N may be any number),the operand may be an operand having a variable estimation pattern.

The stack frame analysis component 216 generates stack frame blockscorresponding to the variable estimation patterns based on the variableestimation patterns. The stack frame analysis component 216 sorts thestack frame blocks based on a location in a stack frame, calculates aninitial value regarding a size of a variable corresponding to eachblock, and stores the initial value in each stack frame block. Thestructure of the stack frame block will be described later withreference to FIG. 6.

The stack frame analysis component 216 may provide the stack frameinformation 14 including the stack frame blocks to the typedetermination unit 230.

Hereinafter, the operation of the variable information collection unit210 will be described with reference to FIG. 4. In interpreting theoperation of the variable information collection unit 210, the contentsdescribed above with reference to FIG. 3 regarding the assembly codepreprocessing component 212, the register analysis component 214, andthe stack frame analysis component 216 may be reflected.

First, step S410 may be performed by the assembly code preprocessingcomponent 212. In step S410, the target binary 10 may be input, andassembly code corresponding to the target binary 10 may be preprocessed.Specifically, the target binary 10 composed of machine language may bedisassembled to generate assembly code, and the assembly code may beclassified and stored for each user-defined function. In addition, theassembly codes classified for each user-defined function may bestructured in units of assembly instructions. For example, a list may beconstructed in which each instruction included in the assembly code maybe a node.

Steps S420 to S440 may be performed by the register analysis component214.

In step S420, general purpose register initialization instructions maybe identified from the structured assembly instructions, and a generalpurpose register unique identification value may be given to thestructured assembly instructions.

Within one user function, each general purpose register (EAX, EBX, ECX,EDX register, etc.) may be used multiple times to store values ofdifferent variables. In order to distinguish which variable each generalpurpose register used as an operand of each assembly instructioncorresponds to, initialization instructions of the general purposeregister may be identified, and a unique identification value may begiven each time the general purpose register may be initialized.

Assembly instructions for initializing a general purpose registerinclude ‘mov,’ ‘lea,’ and ‘xor’ instructions (including similarinstructions ‘movb,’ ‘movw,’ ‘mov1,’ etc.). Based on an instruction inwhich the general purpose registers may be used as a second operand ofthe initialization instructions may be found, a unique identificationvalue that identifies a general purpose register may be given, therebymodifying an instruction. In addition, based on an instruction ofsubsequent instructions not corresponding to the initializationinstruction, the instruction may be modified by reflecting a generalpurpose register unique identification value previously given.

FIG. 5A is a diagram for explaining an example in which a generalregister unique identification value may be given to an assemblyinstruction according to the method. In a table shown in FIG. 5A, asecond column describes original assembly code, and a third columndescribes modified assembly code to give a unique identification valueto general purpose registers. Portions highlighted in bold in the secondcolumn represent instructions for initializing general purpose registersand general purpose registers to be initialized. Portions highlighted inbold in the third column represent modified instructions by assigningnew unique identification values to general purpose registers.Underlined portions in the third column represent modified instructionby reflecting a previous unique identification value for general purposeregisters as it is.

Rows #04 to #07 of FIG. 5A may be instructions corresponding to aninitialization instruction (one of ‘mov,’ ‘lea,’ or ‘xor’) for generalpurpose registers (EAX, EBX, ECX, and EDX). Referring to the thirdcolumn, unique identification values for distinguishing the eax, ebx,ecx, and edx registers may be given and modified to eax1, ebx1, ecx1,and edx1, respectively. Instructions on rows #08 to #09 in FIG. 5A donot correspond to an instruction for initializing a general purposeregister. The eax register described in instructions in rows #08 to #09was modified to eax1 by maintaining a previous unique identificationvalue for the eax register. Instructions in row #10 of FIG. 5A includesan instruction (‘mov’) to re-initialize the eax register. A new uniqueidentification value eax2, which may be distinguished from the previousunique identification value eax1, may be given, and the instruction maybe modified. It may be understood that instructions in rows #11 to #22of FIG. 5A may also be modified to be given a new unique identificationvalue for a new general purpose register for each instruction thatinitializes a general purpose register in the same manner as above.

It will be described with reference to FIG. 4 again. In step S430,modified instructions may be analyzed by assigning a uniqueidentification value to general purpose registers in step S420 describedabove, and final values assigned to each unique general purpose register(general purpose registers given with unique identification values suchas eax1, eax2, ebx1, ebx2, etc.) may be traced.

First, based on instructions that assign values to each unique generalpurpose register, a value assigned to each unique general purposeregister may be identified. A first column of a table shown in FIG. 5Bshows an exemplary result in which values assigned to the unique generalpurpose registers (eax1, eax2, ebx1, ecx1, edx1) corresponding to thegeneral purpose registers (EAX, EBX, ECX, EDX) may be identified.However, it should be noted that values assigned to the unique generalpurpose registers, which may be exemplarily illustrated in FIG. 5B, maybe separate examples irrelevant to the exemplary assembly codeillustrated in FIG. 5A. It may be noted that, in the first column ofFIG. 5B, values assigned to the unique general purpose registers eax2 toeax7, and ebx1 may be described in a format that refers to values ofdifferent general purpose registers (ebx1, ecx1, etc.).

Next, the final value assigned to the unique general purpose registermay be traced. For example, referring to the first column of the tableof FIG. 5B, a value assigned to eax2 may be 0x4(% ebx1), a valueassigned to ebx1 may be ecx1, and a value assigned to ecx1 may be 0x4(%esp). Based on one tracing a value of eax2 by substituting it in reverseorder, it may be 0x4(% esp). In the same way, the final values of valuesassigned to other unique general purpose registers may be traced andshown in a second column of FIG. 5B.

It will be described with reference to FIG. 4 again. In step S440, amongthe final values of the general purpose registers traced in step S430, aunique general purpose register having a variable estimation pattern maybe identified, and the variable identification information 12 may bestored. As described above, based on an operand of an assemblyinstruction being 0xN(% ebp) or −0xN(% ebp) (where N may be any number),the operand may be an operand having a variable estimation pattern.

In the second column of the table shown in FIG. 5B, the final valueassigned to the unique general purpose register edx1 has a variableestimation pattern as ‘−0x50(% ebp).’ In the assembly code of theuser-defined function, the value stored in the unique general purposeregister edx1 may be likely to correspond to a local variable of theuser function. In the assembly code of the user-defined function, basedon edx1 being used as an operand of an assembly instruction or aparameter (argument) of a standard library function, it may be used toinfer the type and size of variables based on such assembly instructionpatterns or standard library function patterns. This will be describedlater with reference to FIGS. 7 and 10.

In some embodiments, in step S440, the variable identificationinformation 12, which may be a result of identifying unique generalpurpose registers having a variable estimation pattern in one userfunction, may be stored, for example, in the form of FIG. 5C. However,it may be noted that data exemplarily illustrated in FIG. 5C do notreflect the final values of the unique general purpose registers of FIG.5B, and may be merely for illustrative purposes of the format in whichthe variable identification information 12 may be stored in someembodiments.

Hereinafter, a process of analyzing a stack frame will be described withreference to steps S450 to S460 of FIG. 4. Steps S450 to S460 may beperformed, for example, by the stack frame analysis component 216.

In step S450, by analyzing the structured assembly instructions for eachuser function, variable estimation patterns may be identified, and stackframe blocks corresponding to the variable estimation patterns may begenerated therefrom.

For example, based on variable estimation patterns found in assemblycode corresponding to a user function being “−0x44(% ebp),” “−0x18(%ebp),” “−0x10(% ebp),” “−0x56(% ebp),” “−0x1c(% ebp),” 5 stack frameblocks corresponding to each may be generated. The stack frame blocksmay include information as shown in Table 1 below.

TABLE 1 Item Description localType variable type classification 0:parameter 1: local variable variableID EBP pattern string estimated tobe a variable ebpDistance distance from an address pointed to by EBP(relative address) variableSize (inferred) variable size variableType(inferred) variable type inferenceLevel Inference level 1: inferencewith an integer type-related instruction pattern 2: inference with astring-related instruction pattern 3: inference with a standard libraryfunction pattern 4: inference with a floating point-related instructionpattern

In addition, in step S450, the generated stack frame blocks may besorted based on the ebpDistance. The ebpDistance of the stack frameblocks indicates a location where a variable corresponding to the stackframe block may be stored in the stack frame.

In step S460, the inferred size of the variable corresponding to thestack frame block may be computed based on an ebpDistance differencefrom the next stack frame block. The computed size may be stored in avariableSize field of the stack frame block.

FIG. 6 is an example of the stack frame information 14 includinginformation on stack frame blocks. FIG. 6 shows the results in whichbased on variable estimation patterns found in the assembly codecorresponding to the user function may be “−0x44(% ebp),” “−0x18(%ebp),” “−0x10(% ebp),” “−0x56(% ebp),” “−0x1c(% ebp),” stack frameblocks corresponding to them may be generated and sorted in steps S450and S460, and a size of a variable corresponding to each may beinferred.

Referring to FIG. 6, it may be seen that the generated stack frameblocks may be sorted in descending order based on ebpDistance in stepS450. In addition, referring to FIG. 6, it may be seen in step S460 thatthe inferred size of the variable corresponding to the stack frame blockmay be computed based on the ebpDistance difference from the next stackframe block, and stored in the variableSize field. The computed size maybe an initial value inferred based on the stack frame analysis describedso far, and may be changed in a process of finally determining thevariable type and size in the future (see descriptions regarding toFIGS. 11 and 12 to be described later). Meanwhile, a variableType fieldand an inferenceLevel field may be finally determined and recorded in aprocess of determining a variable type (see description regarding toFIG. 11 to be described later) through a process of inferring a type ofa variable (see description regarding to FIGS. 7 to 10 to be describedlater).

Information on the stack frame blocks generated and initialized asdescribed above may be stored as the stack frame information 14 andprovided to the type determination unit 230.

So far, the configuration and operation of the variable informationcollection unit 210 of the device 200 for inferring the type of thevariable have been described with reference to FIGS. 3 to 6.Hereinafter, the configuration and operation of the type inference unit220 will be described with reference to FIGS. 7 to 10.

FIG. 7 is a block diagram of the type inference unit 220. The typeinference unit 220 includes a variable type inference executioncomponent 222, and may include at least one of an instruction pattern DB224 and a standard library pattern DB 226. The type inference unit 220generates the variable type inference information 16 from the assemblycode structured for each user function based on the variableidentification information 12 and the type inference pattern informationprovided from the variable information collection unit 210.

The variable type inference execution component 222 reads the assemblycode structured for each user function in units of instructions, anddetermines a correspondence to a variable type inferable assemblyinstruction (OPCODE) pattern or an instruction pattern that calls avariable type inferable standard library function. Here, the variabletype inferable assembly instruction may be identified with reference tothe instruction pattern DB 224. In addition, the variable type inferablestandard library function may be identified with reference to thestandard library function pattern DB 226.

Based on an assembly instruction corresponding to the instructionpattern, the variable type inference execution component 222 determineswhether an operand of the assembly instruction or a parameter (factor)of a standard library function corresponds to one of variable estimationpatterns (for example, the unique general purpose register described inFIG. 5C.) included in the variable identification information 12. Basedon there being a variable estimation pattern corresponding to theoperand or parameter, the instruction may be used for variable typeinference. More specifically, a variable type known to have the operandof the assembly instruction (OPCODE) of the instruction or a variabletype known to have the parameter of the standard library function may beinferred as a type of a variable corresponding to the variableestimation pattern. More details of variable type inference based on thevariable type inferable assembly instruction (OPCODE) pattern or thevariable type inferable standard library function pattern will bedescribed later with reference to FIGS. 8 to 10.

The variable type inference information 16 includes information on atype of a variable and the reliability of the inference. The variabletype inference information 16 generated by the inference by the typeinference unit 220 may be provided to the type determination unit 230 tobe described later.

Hereinafter, the operation of the type inference unit 220 will bedescribed with reference to FIG. 8. In interpreting the operation of thetype inference unit 220, the contents as described above with referenceto FIG. 7 may be reflected.

First, in step S810, the assembly code structured for each user functiondescribed above may be loaded in units of instructions. Instructions ofthe structured assembly code may be given unique register uniqueidentification values by the variable information collection unit 210described above.

Subsequently, in step S820, an assembly instruction (OPCODE orcorresponding mnemonic) of each instruction may be identified.

Steps S830 to S860, which will be described below, may be processes ofinferring a type of a variable based on an assembly instruction pattern.

In step S830, it may be determined whether a command of the instructionmay be a variable type inferable instruction. Based on the command ofthe instruction being a variable type inferable instruction, an operandtype pattern of the command of the instruction may be inquired in stepS840. Here, the pattern may be inquired from the instruction pattern DB224.

A table shown in FIG. 9 is a table including exemplary assemblyinstructions that may be used for variable type inference andinformation on variable types of their operands.

For example, Nos. 1 to 4 of the table in FIG. 9 may be integertype-related instructions. These instructions perform an operation onoperands 1 and 2 with integer type data It may be inferred thatvariables used as operands of these instructions would correspond tointeger variable types. On the other hand, Nos. 5 to 24 of FIG. 9 may bestring-related instructions. At least one of operands 1 or 2 of theseinstructions corresponds to string type data, and based on this, it maybe inferred that variables used as operands of these instructions wouldcorrespond to char(n) or ptr4 types. In addition, Nos. 25 to 27 of FIG.9 may be floating point-related instructions, and it may be inferredthat variables used as operands of these instructions would correspondto variable types such as ‘float4,’ ‘double8,’ or the like.

Here, the reliability of the inference may be given differently. Forexample, as described in the last column of the table shown in FIG. 9,variable type inference based on an integer type-related instruction maybe given the lowest reliability level of 1, the reliability of variabletype inference based on a string-related instruction may be given as 2,and variable type inference based on a floating point-relatedinstruction may be given the highest reliability level of 4.

In step S850, a final value of a register used as an operand of aninstruction having the instruction pattern may be identified. The finalvalue may be a final value derived as a result of performing step S430described with reference to FIG. 4 regarding the operation of thevariable information collection unit 210. For example, based on anoperand of the instruction being edx1, ‘−0x50(% ebp)’ may be identifiedas a final value by referring to a final value tracing result of theedx1 register shown in the second column of FIG. 5B.

In step S860, based on the final value having a variable estimationpattern (0xN(% ebp) or −0xN(% ebp)), inference information on the typeof the variable may be stored. For example, since an operand of theinstruction may be edx1, a final value tracing result of the edx1register may be ‘−0x50(% ebp)’, and ‘−0x50(% ebp)’ has a variableestimation pattern, a type of a variable corresponding to ‘−0x50(% ebp)’may be inferred by referring to the instruction (OPCODE) pattern of theinstruction.

Each information inferred may be stored as the variable type inferenceinformation 16, respectively. The variable type inference information 16includes information on a type of a variable and the reliability of theinference. The variable type inference information 16 may be provided tothe variable type determination component 232 to be described later.

Steps S870 to S900, which will be described below, may be processes forinferring a type of a variable based on a standard library functionpattern. In step S830 described above, based on it being determined thatthe command of the instruction may not be a variable type inferableinstruction, it proceeds to step S870.

In step S870, it may be determined whether the command of theinstruction may be an instruction that calls a variable type inferablestandard library function. In step S880, a parameter type pattern of thestandard library function may be inquired. Here, the pattern may beinquired from the standard library function pattern DB 226.

In the standard library functions, as shown in FIG. 10A, a type of areturn value of a function, the number and type of parameters, or thelike may be pre-determined, and information on this may already beknown. The type of data used as the return value or parameter of thestandard library function may be inferred.

For example, it will be described with reference to assembly codeinstructions shown in FIG. 10B. An instruction of a fifth row of codeshown in FIG. 10B may be an instruction to call the ‘strncpy’ function,which may be one of the standard library functions. In addition, a firstto fourth row instructions preceding the instruction may be instructionsthat store parameters to be passed to a ‘strncpy’ function in a stack.In addition, an instruction in a sixth row may be an instruction thatstores a value of a register in which a return value of the ‘strncpy’function may be stored in a stack. Based on storage spaces being used tostore values of parameters of the ‘stmcpy’ function correspond to thevariable identification information 12 as shown in FIG. 5C, a variabletype may be inferred based on information already given about the typeof the parameter of the ‘strncpy’ function.

The reliability of the inference based on the standard library functionpattern may be given a value higher than the reliability of variabletype inference based on a string-related instruction and lower than thereliability of variable type inference based on a floating-point relatedinstruction. For example, the reliability of the inference based on thestandard library function pattern may be given 3.

In step S890, the final value of the register used as the parameter ofthe standard library function may be identified. Step S890 may beperformed in a similar manner to step S850.

In step S900, based on the final value having a variable estimationpattern, inference information on the type of the variable may bestored. Step S900 may be performed in a similar manner to step S860.

Each of information inferred may be stored as the variable typeinference information 16, respectively. The variable type inferenceinformation 16 includes information on a type of a variable and thereliability of the inference. The variable type inference information 16may be provided to the variable type determination component 232 to bedescribed later.

So far, the configuration and operation of the type inference unit 210of the device 200 for inferring the type of the variable have beendescribed with reference to FIGS. 7 to 10. Hereinafter, theconfiguration and operation of the type determination unit 230 will bedescribed with reference to FIGS. 11 to 12.

FIG. 11 is a block diagram of the type determination unit 230. The typedetermination unit 230 may include a variable type determinationcomponent 232 and a variable size determination component 234. The typedetermination unit 230 finally determines each variable type and arraysize for each user function by synthesizing the variable type inferenceinformation 16 provided by the type inference unit 220 and the stackframe information 14 provided by the variable information collectionunit 210. Variable type and array size information 20 generated by thetype determination unit 230 may be used in the process of patching thevulnerability of the binary as described above.

The variable type determination component 232 determines a variable typebased on the variable type inference information 16. Based on therebeing one variable type inference information 16 for any one variable, avariable type indicated by the one variable type inference information16 may be determined as the type of the variable.

However, the variable type inference execution component 222 of the typeinference unit 220 described above reads structured assembly code foreach user function in units of instructions. Then, it determines whethereach instruction corresponds to a variable type inferable instruction orfunction, and generates the variable type inference information 16therefrom. A plurality of variable type inference information 16 aboutthe same variable may be generated from a plurality of instructions in auser function. Based on the types of the variables indicated by theplurality of variable type inference information 16 about the samevariable being different from each other, one of these types may bedetermined as the type of the variable.

The variable type determination component 232 reads the variable typeinference information 16 in units of variables, and determines whetherthe variable type inference information 16 corresponding to the variableindicates two or more different types. Based on it indicating to two ormore types, the variable type inference information 16 having thehighest inference reliability may be selected among the variable typeinference information 16. In some embodiments, the reliability ofinformation inferred based on a floating point-related instructionpattern may be 4, the reliability of information inferred based on astring-related command pattern may be 2, and the reliability inferredbased on an integer type-related instruction pattern may be 1. Thereliability of information inferred based on a standard library functionpattern may be 3. Based on the variable type inference information 16having the highest inference reliability among the variable typeinference information 16 may be selected, it may be determined as thetype of the variable.

If the reliabilities of the variable type inference information 16 maybe the same, a type having a large number of variable type inferenceinformation 16 may be determined as the type of the variable. Forexample, based on 3 pieces of information indicating an ‘int4’ type and2 pieces of information indicate a ‘float4’ type among 5 pieces of thevariable type inference information 16 on a variable, the type of thevariable may be determined as the ‘int4’ type.

As described above, information on the type of variables determined bythe variable type determination component 232 may be reflected in astack frame block corresponding to each variable, which may be includedin the stack frame information 14 provided by the stack frame analysiscomponent 216 of the variable information collection unit 210.

Hereinafter, a process of determining a size of a variable based on thestack frame information 14 reflecting information on the variable typeby the variable size determination component 234 of the typedetermination unit 23 will be described with reference to FIGS. 12A and12B.

First, in step S1210, the stack frame information 14 may be loaded inunits of stack frame blocks. The stack frame information 14 may have aformat such as a table shown in FIG. 6, for example. Variable typeinformation determined by the type determination component 232 describedabove for each variable may be additionally included in the stack frameinformation 14.

In step S1220, variable type information described in a first stackframe block may be identified.

In step S1230, it may be determined whether the variable typeinformation indicates that it may be an ‘array(n) or ptr4’ type. Basedon the variable type information not indicating that it may be the‘array(n) or ptr4’ type, it proceeds to step S1250.

If the variable type information indicates that it may be the ‘array(n)or ptr4’ type, steps S1231 to S1234 may be performed to determine whichof the ‘array(n)’ and ‘ptr4’ types.

In step S1231, a second stack frame block, which may be a next block ofthe first stack frame block, may be identified. Based on variable typeinformation being recorded in the second stack frame block, a variablecorresponding to the first stack frame block may be determined to be avariable of type ‘ptr4’, and a size may be determined to be a size ofthe ‘ptr4’ type, for example, 4 bytes (step S1232). Based on no variabletype information being recorded in the second stack frame blocksubsequent to the first stack frame, the second stack frame block may bedeleted (step S1233). In addition, a variable corresponding to the firststack frame block may be determined to be an ‘array(n)’ type, that maybe, an array (step S1234). Although not shown, in some embodiments, asize of the variable corresponding to the first stack frame block may becorrected by adding a size of a variable recorded in the second stackframe block to a variable described in the first stack frame block.Further, it may be determined whether variable type information may berecorded for a third stack frame block subsequent to the second stackframe. Based on there being no recorded variable type information, aprocess of summing a size of a variable recorded in the third stackframe block to the size of the variable described in the first stackframe block may be repeated.

Through the operations described above, the type and size of a variablecorresponding to the first stack frame block may be finally determined.

In step S1230, based on the variable type information described in thefirst stack frame block not indicating that it may be the ‘array(n) orptr4’ type, it proceeds to step S1250.

In step S1250, it may be determined whether a size corresponding to thetype of the variable recorded in the first stack frame block exceeds thesize of the variable recorded in the first stack frame block. Based onthe size corresponding to the type of the variable recorded in the firststack frame block not exceeding the size of the variable recorded in thefirst stack frame block, the type of the variable recorded in the firststack frame block and the size corresponding to the type may be finallydetermined as the type and size of the variable corresponding to theblock (not shown).

If the size corresponding to the type of the variable recorded in thefirst stack frame block exceeds the size of the variable recorded in thefirst stack frame block, a second stack frame block subsequent to thefirst stack frame block may be identified. Based on variable typeinformation being recorded in the second stack frame block (step S1251),the reliability of the variable type inference information recorded inthe first stack frame block and the reliability of the variable typeinference information recorded in the second stack frame may be comparedwith each other (step S1252).

If the reliability of the variable type inference information recordedin the first stack frame block may be lower than the reliability of thevariable type inference information recorded in the second stack frameblock, the first stack frame block may be deleted. In other words, theinformation described in the first stack frame block may be discarded(step S1253).

If, in step S1251, variable type information may be not recorded in thesecond stack frame block, or based on, in step S1252, the reliability ofthe variable type inference information recorded in the first stackframe block being greater than or equal to the reliability of thevariable type inference information described in the second stack frameblock, it proceeds to step S1254.

In step S1254, the second stack frame block may be deleted. In otherwords, the information described in the second stack frame block may bediscarded.

In step S1255, the size corresponding to the type of the variablerecorded in the first stack frame block may be finally determined as thesize of the variable corresponding to the first stack frame block.

Although not shown, the steps S1210 to S1255 may be performed repeatedlyfor all stack frame blocks included in the stack frame information 14,so that the types and sizes of variables declared in a user functioncorresponding to the stack frame information may finally be determined.

So far, referring to FIGS. 11, 12A, and 12B, the configuration of thetype determination unit 230 of the 200 device for inferring the type ofthe variable, and a process of the type determination unit 230 finallydetermining the type and size of the variables based on the variabletype inference information 16 and the stack frame information 14 hasbeen described. As described above, the information 20 on the type andsize of the variable calculated by the type determination unit 230 maybe used in a process of patching a binary vulnerability.

The technical features of the present disclosure described so far may beembodied as computer readable codes on a computer readable medium. Thecomputer readable medium may be, for example, a removable recordingmedium (CD, DVD, Blu-ray disc, USB storage device, removable hard disk)or a fixed recording medium (ROM, RAM, computer equipped hard disk). Thecomputer program recorded on the computer readable medium may betransmitted to other computing device via a network such as internet andinstalled in the other computing device, thereby being used in the othercomputing device.

In the above description, it is described that all the componentsconstituting the embodiments of the present disclosure may be combinedor operated as one, but the technical features of the present disclosureare not limited to these embodiments. That is, within the scope of thepresent disclosure, all of the components may be selectively combinedand operated in one or more combinations.

Although the operations are shown in a specific order in the drawings,those skilled in the art will appreciate that many variations andmodifications can be made to the embodiments without substantiallydeparting from the principles of the present disclosure. The disclosedembodiments of the present disclosure are used in a generic anddescriptive sense and not for purposes of limitation. The scope ofprotection of the present disclosure should be interpreted by thefollowing claims, and all technical ideas within the scope equivalentthereto should be construed as being included in the scope of thetechnical idea defined by the present disclosure.

What is claimed is:
 1. A method for identifying a type of a variablewithin a binary, the method being performed on a computing device, andcomprising: identifying a variable from disassembly code of a binary;and determining a type of the variable based on an instruction of thedisassembly code associated with the variable.
 2. The method of claim 1,wherein identifying the variable comprises identifying an operand as thevariable, the operand accessing a memory using a base pointer registerand an index value.
 3. The method of claim 2, wherein identifying thevariable comprises: analyzing the instructions of the disassembly codeand tracing a final value of a value assigned to a general register; andidentifying the general purpose register as the variable based on thetraced final value being a value obtained by accessing the memory usingthe base pointer register and the index, and wherein the tracingcomprises substituting the final value obtained by tracing a valueassigned to a different register into the value assigned to the generalpurpose register based on the value assigned to the general purposeregister referring to the different register.
 4. The method of claim 1,wherein determining the type of the variable comprises inferring thetype of the variable based on at least one of an instruction using thevariable as an operand and a standard library function using thevariable as a parameter.
 5. The method of claim 4, wherein inferring thetype of the variable comprises: determining a plurality of variable typecandidates based on a plurality of instructions associated with thevariable; and determining the type of the variable based on theplurality of variable type candidates.
 6. The method of claim 5, whereindetermining the type of the variable comprises determining the variabletype candidate the count of which is the most among the plurality ofdifferent variable type candidates for the variable as the type of thevariable.
 7. The method of claim 5, wherein determining the plurality ofvariable type candidates comprises giving an inference reliabilitycorresponding to the instruction or the standard library function thatis the basis of inference of the type of the variable to the variabletype candidate, and wherein determining the type of the variablecomprises determining, among the plurality of different variable typecandidates for the variable, the variable type candidate having thehighest inference reliability given as the type of the variable.
 8. Themethod of claim 7, wherein an integer instruction among the instructionscorresponds to a first inference reliability, wherein a stringinstruction among the instructions corresponds to a second inferencereliability higher than the first inference reliability wherein thestandard library function corresponds to a third inference reliabilityhigher than the second inference reliability, and wherein a floatingpoint instruction among the instructions corresponds to a fourthinference reliability higher than the third inference reliability.
 9. Amethod for identifying a size of a variable in a binary, the methodbeing performed on a computing device, and comprising: identifying aplurality of variables from disassembly code of a binary; determining,for each of the plurality of variables, an initial value of the size ofthe variable; and determining, for each of the plurality of variables,the size of the variable based on an inferred variable type and theinitial value of the size of the variable.
 10. The method of claim 9,wherein identifying the plurality of variables comprises identifying anoperand as the variable, the operand accessing a memory using a basepointer register and an index value, wherein determining the initialvalue of the size of the variable comprise: sorting the plurality ofidentified variables based on a relative address within the memory togenerate a sorted variable list; and determining, for each of theplurality of variables, a difference of the relative address within thememory with a next variable on the sorted variable list as the initialvalue of the size of the variable, and wherein the relative addresswithin the memory is the index value.
 11. The method of claim 10,further comprising: inferring a type of each variable based on at leastone of an instruction using each variable as an operand and a standardlibrary function using each variable as a parameter.
 12. The method ofclaim 11, wherein inferring the type of each variable comprise:determining a plurality of variable type candidates for each variablebased on a plurality of instructions targeting each variable; anddetermining the type of each variable based on the plurality of variabletype candidates.
 13. The method of claim 10, wherein determining thesize of the variable comprises: identifying a first variable included inthe sorted variable list and a second variable subsequent to the firstvariable on the sorted variable list; based on an inferred variable typeof the first variable being one of an array type and a pointer type,determining whether an inferred variable type for the second variableexists; in response to determining that the inferred variable type forthe second variable exists, determining the type of the first variableas the pointer type and determining the size of the first variable asthe size corresponding to the pointer type; and in response todetermining that there is no inferred variable type for the secondvariable, determining the type of the first variable as the array type,and determining the initial value of the size of the variable of thefirst variable as the size of the first variable.
 14. The method ofclaim 10, wherein determining the size of the variable comprises:identifying a first variable included in the sorted variable list and asecond variable subsequent to the first variable on the sorted variablelist; based on the size corresponding to an inferred variable type ofthe first variable being greater than the initial value of the size ofthe variable of the first variable, determining whether an inferredvariable type for the second variable exists; in response to determiningthat the inferred variable type for the second variable exists,comparing an inference reliability of the type of the first variablewith an inference reliability of the type of the second variable andremoving one of the first variable and the second variable; and inresponse to determining that there is no inferred variable type for thesecond variable, determining the size corresponding to the inferredvariable type of the first variable as the size of the first variable.15. A device for identifying a type of a variable in a binary,comprising: a variable information collection unit; a variable typeinference unit; and a variable type determination unit, wherein thevariable information collection unit: analyzes disassembly code of thebinary, and identifying a plurality of operands as each variable, theoperands accessing a memory using a base pointer register and an indexvalue; and determines an initial value of a variable size for eachvariable based on the index value corresponding to each variable,wherein the variable type inference unit determines a variable typecandidate for each variable based on at least one of an instructionusing each variable as an operand and a standard library function usingeach variable as a parameter, and inferring the type of each variablebased on the variable type candidate, and wherein the variable typedetermination unit determines the type and size of each variable basedon the inferred type of the variable and the initial value of thevariable size.